<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
    <meta name="renderer" content="webkit">
    <title></title>
    <link rel="stylesheet" href="__ROOT__/static/admin/css/pintuer.css">
    <link rel="stylesheet" href="__ROOT__/static/admin/css/admin.css">
    <script src="__ROOT__/static/admin/js/jquery.js"></script>
    <script src="__ROOT__/static/admin/js/pintuer.js"></script>
    <script src="__ROOT__/static/plugins/layer/layer.min.js"></script>
    <style>
        .show_file{
            padding: 0px 10px;
            height: 40px;
            line-height: 40px;
            position: relative;
            cursor: pointer;
            color: #fff;
            background: #00AAEE;
            border: 1px solid #ddd;
            border-radius: 4px;
            overflow: hidden;
            display: inline-block;
            *display: inline;
            *zoom: 1
        }

        .show_file input{
            position: absolute;
            font-size: 100px;
            right: 0;
            top: 0;
            opacity: 0;
            filter: alpha(opacity=0);
            cursor: pointer
        }

        .show_file:hover {
            color: #fff;
            background: #0099CC;
            border-color: #ccc;
            text-decoration: none
        }
    </style>
</head>
<body>
<div class="panel admin-panel">
    <div class="panel-head" id="add"><strong><span class="icon-pencil-square-o"></span>修改内容</strong></div>
    <div class="body-content">
        <input type="hidden" name="id" id="know_id"  value="{$row.id}" />
        <div   class="form-x">
            <div class="form-group">
                <div class="label">
                    <label>标题：</label>
                </div>
                <div class="field">
                    <input type="text" class="input w50" value="{$row.parenting_title}" id="parenting_title" data-validate="required:请输入标题" />
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>图片：</label>
                </div>
                <div class="field">
                    <span ><img id="image" style="width: 300px ;height: 300px " class="image_url" src="__ROOT__{$row.album_url}"></span>
                    <div class="show_file">
                        <form id="upload" action="" enctype="multipart/form-data">
                            <input type="file" class="button bg-blue margin-left" id='album_url' onchange="upload()" name="img" style="float:left;">
                        </form>
                        <span id="image1">浏览上传</span>
                    </div>
                </div>
            </div>

            <if condition="$iscid eq 1">
                <div class="form-group">
                    <div class="label">
                        <label>分类标题：</label>
                    </div>
                    <div class="field">
                        <select name="cid1" class="input w50"  id="knows_name"  onchange="knows_name(this)"  >
                            <option value="0">请选择分类</option>
                            {volist name='res' id="vo"}
                            <option  value="{$vo['id']}">{$vo.know_name}</option>
                            {/volist}
                        </select>
                        <select name="cid2" class="input w50"  id="knows_name2"    >
                            <option value="0">请选择分类</option>
                        </select>

                        <div class="tips"></div>
                    </div>
                </div>
                <div class="form-group">
                    <div class="label">
                        <label>其他属性：</label>
                    </div>
                    <div class="field" style="padding-top:8px;">
                        首页 <input id="is_home" name="is_home" type="checkbox" value="0" onclick="is_home('is_home')"/>
                        推荐 <input id="is_vouch"  name="is_vouch" type="checkbox" value="0"  onclick="is_vouch('is_vouch')" />
                        置顶 <input id="is_top" name="is_top" type="checkbox" value="0"  onclick="is_top('is_top')" />

                    </div>
                </div>
            </if>

            <div class="form-group">
                <div class="label">
                    <label>内容：</label>
                </div>
                <div class="field">
                    <textarea name="content" class="input" id="parenting_content" style="height:450px; border:1px solid #ddd;">{$row.parenting_content}</textarea>
                    <div class="tips"></div>
                </div>
            </div>

            <div class="clear"></div>
            <div class="form-group">
                <div class="label">
                    <label>关键字标题：</label>
                </div>
                <div class="field">
                    <input type="text" class="input"id="know_title" name="know_title" value="{$row.know_title}" />
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>内容关键字：</label>
                </div>
                <div class="field">
                    <input type="text" class="input"id="know_key" name="know_key" value="{$row.know_key}"/>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>关键字描述：</label>
                </div>
                <div class="field">
                    <textarea type="text" class="input" id="know_describe" name="know_describe" style="height:80px;">{$row.know_describe}</textarea>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label>排序：</label>
                </div>
                <div class="field">
                    <input type="text" class="input w50" id="sorts" value="{$row.sorts}"  data-validate="number:排序必须为数字" />
                    <div class="tips"></div>
                </div>
            </div>
            <div class="form-group">
                <div class="label">
                    <label></label>
                </div>
                <div class="field">
                    <button class="button bg-main icon-check-square-o" type="submit" onclick="submit()"> 提交</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    //首页
    function is_home() {
        var obj = document.getElementsByName("is_home");
        if(obj[0].checked){
            obj[0].value='1';
        }else{
            obj[0].value='0';
        }
    }
    function is_vouch() {
        var obj = document.getElementsByName("is_vouch");
        if(obj[0].checked){
            obj[0].value='1';
        }else{
            obj[0].value='0';
        }
    }

    function is_top() {
        var obj = document.getElementsByName("is_top");
        if(obj[0].checked){
            obj[0].value='1';
        }else{
            obj[0].value='0';
        }
    }
    
    
    //三级联动 ajax获取二级分类
    function  knows_name(obj){
        var id= $(obj).val();
        var params={};
        params.areaId=id;
        $.post("{:url('admin/Knows/getKnowsId')}",params,function(data){
            var obj2= JSON.parse(data);
            var html=[];
            html.push('<option  value="0">请选择分类</option>');
            $(obj2).each(function(index,element){
                html.push('<option value="'+this.id+'">'+this.know_name+'</option>');
            });
            html=html.join('');
            $('#knows_name2').html(html);
            $("#countyId").html("<option>请选择分类</option>");
        })
    }


    /*上传图片*/
    function upload() {
        var formData = new FormData($('#upload')[0]);
        $.ajax({
            cache: false,
            type: "POST",
            url: "{:url('admin/Knows/addKnowsList')}",
            data: formData,
            async: false,
            contentType: false,
            processData: false,
            success: function (data) {
                //把上传路径写到数据库
                var params = {};
                params.album_url = data;
                $('#image').attr("src",'__ROOT__/'+params.album_url);
            }
        });
    }
     // 提交
    function submit() {
        var data = {};
        data.ids = $('#know_id').val();
        data.parenting_title = $('#parenting_title').val();
        data.parenting_content = $('#parenting_content').val();
        data.album_url = $('.image_url').attr('src');
        data.id = $('#knows_name').val();
        data.knows_type_id2 = $('#knows_name2').val();
        data.is_home = $('#is_home').val();
        data.is_vouch = $('#is_vouch').val();
        data.is_top = $('#is_top').val();
        data.know_title = $('#know_title').val();
        data.know_key = $('#know_key').val();
        data.know_describe = $('#know_describe').val();
        data.sorts = $('#sorts').val();
        $.post("{:url('admin/Knows/updateKnowsList')}",data, function (response) {
            console.dir(response);
            if(response > 0){
                layer.msg('修改成功', {icon: 5});
                window.location.href = "{:url('admin/Knows/index')}";
            }else {
                layer.msg('修改失败', {icon: 5});

            }

        });
    }




</script>
</body>
</html>